# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This patch file is dual-licensed. It is available under the license the
# patched project is licensed under, as long as it is an OpenSource license
# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
# of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# --- SDE-COPYRIGHT-NOTE-END ---

--- ./tools/lvmcmdline.c.orig	2012-11-24 19:32:51.319288478 +0100
+++ ./tools/lvmcmdline.c	2012-11-24 19:34:46.381960596 +0100
@@ -1194,9 +1194,12 @@
 static int _check_standard_fds(void)
 {
 	int err = is_valid_fd(STDERR_FILENO);
+	FILE *stdin_stream = stdin;
+	FILE *stdout_stream = stdout;
+	FILE *stderr_stream = stderr;
 
 	if (!is_valid_fd(STDIN_FILENO) &&
-	    !(stdin = fopen(_PATH_DEVNULL, "r"))) {
+	    !(stdin_stream = fopen(_PATH_DEVNULL, "r"))) {
 		if (err)
 			perror("stdin stream open");
 		else
@@ -1206,7 +1209,7 @@
 	}
 
 	if (!is_valid_fd(STDOUT_FILENO) &&
-	    !(stdout = fopen(_PATH_DEVNULL, "w"))) {
+	    !(stdout_stream = fopen(_PATH_DEVNULL, "w"))) {
 		if (err)
 			perror("stdout stream open");
 		/* else no stdout */
@@ -1214,7 +1217,7 @@
 	}
 
 	if (!is_valid_fd(STDERR_FILENO) &&
-	    !(stderr = fopen(_PATH_DEVNULL, "w"))) {
+	    !(stderr_stream = fopen(_PATH_DEVNULL, "w"))) {
 		printf("stderr stream open: %s\n",
 		       strerror(errno));
 		return 0;
--- ./lib/commands/toolcontext.c.orig	2012-11-24 19:16:13.532208503 +0100
+++ ./lib/commands/toolcontext.c	2012-11-24 19:45:44.053159552 +0100
@@ -1315,6 +1315,8 @@
 {
 	struct cmd_context *cmd;
 	FILE *new_stream;
+	FILE *stdin_stream = stdin;
+	FILE *stdout_stream = stdout;
 
 #ifdef M_MMAP_MAX
 	mallopt(M_MMAP_MAX, 0);
@@ -1359,20 +1361,20 @@
 		}
 
 		if (is_valid_fd(STDIN_FILENO)) {
-			if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream))
+			if (!_reopen_stream(stdin_stream, STDIN_FILENO, "r", "stdin", &new_stream))
 				goto_out;
-			stdin = new_stream;
-			if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) {
+			stdin_stream = new_stream;
+			if (setvbuf(stdin_stream, cmd->linebuffer, _IOLBF, linebuffer_size)) {
 				log_sys_error("setvbuf", "");
 				goto out;
 			}
 		}
 
 		if (is_valid_fd(STDOUT_FILENO)) {
-			if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream))
+			if (!_reopen_stream(stdout_stream, STDOUT_FILENO, "w", "stdout", &new_stream))
 				goto_out;
-			stdout = new_stream;
-			if (setvbuf(stdout, cmd->linebuffer + linebuffer_size,
+			stdout_stream = new_stream;
+			if (setvbuf(stdout_stream, cmd->linebuffer + linebuffer_size,
 				     _IOLBF, linebuffer_size)) {
 				log_sys_error("setvbuf", "");
 				goto out;
@@ -1629,6 +1631,8 @@
 {
 	struct dm_config_tree *cft_cmdline;
 	FILE *new_stream;
+	FILE *stdin_stream = stdin;
+	FILE *stdout_stream = stdout;
 
 	if (cmd->dump_filter)
 		persistent_filter_dump(cmd->filter, 1);
@@ -1655,17 +1659,17 @@
 	if (cmd->linebuffer) {
 		/* Reset stream buffering to defaults */
 		if (is_valid_fd(STDIN_FILENO)) {
-			if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) {
-				stdin = new_stream;
-				setlinebuf(stdin);
+			if (_reopen_stream(stdin_stream, STDIN_FILENO, "r", "stdin", &new_stream)) {
+				stdin_stream = new_stream;
+				setlinebuf(stdin_stream);
 			} else
 				cmd->linebuffer = NULL;	/* Leave buffer in place (deliberate leak) */
 		}
 
 		if (is_valid_fd(STDOUT_FILENO)) {
-			if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) {
-				stdout = new_stream;
-				setlinebuf(stdout);
+			if (_reopen_stream(stdout_stream, STDOUT_FILENO, "w", "stdout", &new_stream)) {
+				stdout_stream = new_stream;
+				setlinebuf(stdout_stream);
 			} else
 				cmd->linebuffer = NULL;	/* Leave buffer in place (deliberate leak) */
 		}
--- a/libdm/mm/pool-fast.c	2012-11-24 19:05:17.413015858 +0100
+++ b/libdm/mm/pool-fast.c	2012-11-24 19:05:56.589926540 +0100
@@ -18,6 +18,7 @@
 #endif
 
 #include "dmlib.h"
+#include <stddef.h>
 #include <malloc.h>
 
 struct chunk {
--- a/daemons/dmeventd/dmeventd.c	2012-11-24 19:08:48.981918074 +0100
+++ b/daemons/dmeventd/dmeventd.c	2012-11-24 19:09:25.822750433 +0100
@@ -37,6 +37,7 @@
 #include <unistd.h>
 #include <signal.h>
 #include <arpa/inet.h>		/* for htonl, ntohl */
+#include <fcntl.h>
 
 #ifdef linux
 /*
--- a/scripts/lvm2_activation_generator_systemd_red_hat.c	2012-11-24 20:06:19.481792514 +0100
+++ b/scripts/lvm2_activation_generator_systemd_red_hat.c	2012-11-24 20:06:56.774634314 +0100
@@ -19,6 +19,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <limits.h>		/* for PATH_MAX */
 #include "lvm2app.h"
 
 #define KMSG_DEV_PATH        "/dev/kmsg"
